import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import('@/views/HomeView.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('@/views/AboutView.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/LoginView.vue')
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/views/RegisterView.vue')
    },
    {
      path: '/forget',
      name: 'forget',
      component: () => import('@/views/ForgetView.vue')
    },
    {
      path: '/forgot-password',
      name: 'forgot-password',
      component: () => import('@/views/ForgotPasswordView.vue')
    },
    {
      path: '/updata-password',
      name: 'updata-password',
      component: () => import('@/views/UpdataPassword.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/profile',
      name: 'profile',
      component: () => import('@/views/ProfileView.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/config',
      name: 'config',
      component: () => import('@/views/ConfigView.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/soundUpload',
      name: 'upload',
      component: () => import('@/views/sound/upload.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/soundChoose',
      name: 'choose',
      component: () => import('@/views/sound/choose.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/prohibited',
      name: 'prohibited',
      component: () => import('@/views/broadcast/prohibited.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/deepseekSet',
      name: 'deepseekSet',
      component: () => import('@/views/deepseek/set.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/deepseekTest',
      name: 'deepseekTest',
      component: () => import('@/views/deepseek/test.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/live',
      name: 'live',
      component: () => import('@/views/LiveView.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/danmuList',
      name: 'danmuList',
      component: () => import('@/views/liveConfig/DanmuList.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/LiveConfig',
      name: 'LiveConfig',
      component: () => import('@/views/liveConfig/LiveConfig.vue'),
      meta: { requiresAuth: true }
    },
    {
			path: '/ChatWsDevPanel',
			name: 'ChatWsDevPanel',
			component: () => import('@/views/ChatWsDevPanel.vue'),
      meta: { requiresAuth: true }
		},
    {
      path: '/DeepseekConfig',
      name: 'DeepseekConfig',
      component: () => import('@/views/liveConfig/DeepseekConfig.vue'),
      meta: { requiresAuth: true }
    }
  ]
})



// 路由守卫，检查用户是否已登录
router.beforeEach((to, from, next) => {
  // 这里可以添加登录验证逻辑
  // 例如检查localStorage中是否有token
  const isAuthenticated = localStorage.getItem('token') !== null
  if (to.meta.requiresAuth && !isAuthenticated) {
    // 如果需要登录但用户未登录，重定向到登录页
    next('/login')
  } else {
    next()
  }
})


export default router